﻿function showMore(element) {
    var index = $(element).attr('id');
    var data = { pageIndex: index };

    $.ajax({
        type: "POST",
        url: "/Home/ShowMoreNew",
        content: "application/json; charset=utf-8",
        dataType: "json",
        data: data,
        success: function (d) {
            if (d.content != "") {
                $('.new-rooms-container').append(d.content);
                var increseIndex = parseInt(index) + 1;
                $('.show-more-new-rooms').attr('id', increseIndex);
            }
            else {
                $('.show-more-new-rooms').remove();
            }
        },
        error: function (xhr, textStatus, errorThrown) {
            // TODO: Show error
        }
    });
}

$(document).ready(function () {
    $('.show-more-new-rooms').click(function (e) {
        e.preventDefault();
        showMore(this);
    });

    $(document).scroll(function () {
        if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
            showMore($('.show-more-new-rooms'));
        }
    });

});
